package top.cn27.luckyhe.mirai.plugin.residence.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ResListUtil {
    public static List<Map<String, String>> getSplitResult(String commandResult) {
        commandResult = commandResult.replaceAll("\r", "\n");
        String[] results = commandResult.split("\n");

        String regex = " \\d+\\. ([\\w-]+) - [\\w-]+ {2}所有者: ([\\w-]+) \\(X:-?\\d+ Y:-?\\d+ Z:-?\\d+;X:-?\\d+ Y:-?\\d+ Z:-?\\d+\\)建造于: 周[一二三四五六日] \\d{4}.\\d{2}.\\d{2} at \\d{2}:\\d{2}:\\d{2} [上下]午 CST";

        List<Map<String, String>> resMaps = new ArrayList<>();

        for (String result : results) {

            String resName = result.replaceAll(regex, "$1");
            if (resName.equals(result)) {
                continue;
            }
            String resOwner = result.replaceAll(regex, "$2");

            Map<String, String> map = new HashMap<>();
            map.put("name", resName);
            map.put("owner", resOwner);

            resMaps.add(map);
        }

        return resMaps;
    }
}
